home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / directsel.lha / direct_selection.opt next >
Encoding:
Text File  |  1987-01-01  |  912 b   |  41 lines

  1. ; from disc # 5
  2. ; --------------------------------------
  3. ; - direct-selection sorting algorithm -
  4. ; - optimized version by JPN/Level 4   -
  5. ; --------------------------------------
  6. org    $40000
  7. load    $40000
  8.  
  9. num_elements=30
  10. a:
  11.         lea    data_list,a0    ; table for elements
  12.         moveq    #00,d0        ; outer loop counter (x)
  13. outer:    
  14.         move.w    d0,d1        ; inner loop counter (y)
  15.         move.w    d0,d2        ; index for smallest (j=x)
  16.         move.w    (a0,d2.w),d3    ; a(j) -> d3        
  17. inner:
  18.         cmp.w    (a0,d1.w),d3    ; a(y) < a(y) ???
  19.         blt.s    smaller
  20.         move.w    d1,d2        ; j=y
  21.         move.w    (a0,d2.w),d3    ; a(j) -> d3            
  22. smaller:
  23.         addq.w    #02,d1        ; next y value
  24.         cmp.w    #num_elements*2,d1
  25.         bne.s    inner        ; next y
  26.         move.w    (a0,d0.w),d4    ; a(x) => d4
  27.         move.w    d3,(a0,d0.w)    
  28.         move.w    d4,(a0,d2.w)
  29.         addq.w    #02,d0        ; next x value
  30.         cmp.w    #num_elements*2,d0
  31.         bne.s    outer
  32.         rts            
  33.  
  34. data_list:
  35.     dc.w 5,2,3,1,6,8,9,7,4,0
  36.     dc.w 5,2,3,-1,6,8,9,7,4,0
  37.     dc.w 5,2,3,1,6,8,9,7,4,0
  38. list_end:
  39.  
  40.  
  41.